package com.game.dubbo;

import com.game.message.Msg;
import com.game.message.task.IProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.SerializationUtils;

/**
 * 实现类
 * Created by Administrator on 2016/6/13.
 */
@Component
public class LogicCenterServiceImpl implements LogicCenterService {
	private static Logger logger = LoggerFactory.getLogger(LogicCenterServiceImpl.class);
	@Autowired
	private DubboProcessorManager processorManager;

	public byte[] service(byte[] msgBytes) {
		Msg msg = (Msg)SerializationUtils.deserialize(msgBytes);
		IProcessor processor = processorManager.getProcess(msg.getMsgId());
		Msg result = null;
		try {
			result = processor.process(msg, null);
		} catch (Exception e) {
			logger.error("dubbo 处理Processor异常,processorId = " + msg.getMsgId(),e);
		}
		logger.info("process my logic....." + processor);
		if (result == null) {
			return null;
		}
		return SerializationUtils.serialize(msg);
	}
}
